import { getArticleCate } from "@/API/article.js";
import { getUserIdenInfo, distinguishOCR, getRichText, getConfig, getPaymentInfo } from "@/API/common.js";
import { getUserWallet } from "@/API/wallet.js";
import { BlindHigher } from "@/API/login.js";
import { upload } from "@/utils/network.js";
import stoarge from "./stoarge.js";

export default {
	/**
	 * 获取文章分类
	 */
	getArticleCategoryList(pid, callBack) {
		getArticleCate(pid).then((res) => {
			callBack & callBack(res.data);
		});
	},
	/**
	 * 获取用户身份信息
	 */
	getUserIdenInfoData(callBack) {
		getUserIdenInfo().then((res) => {
			callBack & callBack(res.data);
		});
	},

	/**
	 * 上传图片
	 */
	onUploadFile(file, callBack) {
		upload(file).then((res) => {
			callBack & callBack(res.data);
		});
	},
	/**
	 * 识别OCR文件
	 */
	onDistinguishOCRData(path, type, callBack) {
		distinguishOCR(path, type).then((res) => {
			callBack & callBack(res.data);
		});
	},
	/**
	 * 获取富文本内容
	 */
	getRichTextData(name, id, callBack) {
		var key = id;
		if (id === "") {
			key = stoarge.getConfigData()[name];
		}
		getRichText(key).then((res) => {
			callBack & callBack(res.data);
		});
	},
	/**
	 * 获取配置信息
	 */
	getConfigData() {
		getConfig().then((res) => {
			stoarge.setConfigData(res.data.appConfig);
		});
	},
	/**
	 * 绑定上下级关系
	 */
	onBindHigher(pid = "") {
		var id = pid;
		if (pid === "") {
			id = stoarge.pid
		}
		BlindHigher(id);
	},
	/**
	 * 获取支付信息
	 */
	getPaymentInfoData(params, callBack) {
		getPaymentInfo(params).then((res) => {
			callBack({code: 1, data: res.data});
		}).catch(() => {
			callBack({code: 0})
		});
	},
	/**
	 * 获取钱包余额
	 */
	getWalletBalanceData(type, callBack) {
		getUserWallet(type).then(res => {
			callBack * callBack(res.data);
		})
	}
};
